<?php

namespace App\Http\Middleware;

use Closure;
use Illuminate\Support\Facades\Auth;


class CheckToken
{
    /**
     * Handle an incoming request.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  \Closure  $next
     * @param  string|null  $guard
     * @return mixed
     */
    public function handle($request, Closure $next, $guard = null)
    {
        $new_time = strtotime($request->user()->updated_at);

        $expired = config('auth.guards.web.expired');
      
        if($expired < time() - $new_time){
            return response()->json(['message' => 'token过期.','code'=>'-1']);
        }

        return $next($request);
    }
}
